﻿@using OA.AspNetCore.Html;
@using OA.Model;
@using OA.Core.Model;
@model CustomForm
@{

    Layout = null;
    string msg = ViewBag.Msg;
    string tips = string.Empty;
    if (!string.IsNullOrWhiteSpace(msg))
    {
        tips = $"layer.msg('{msg}');";
    }
    List<ListItem> formGroups = ViewBag.FormGroups;

    List<ListItem> approvalTrees = ViewBag.ApprovalTrees;

    List<ListItem> listProcessTree = ViewBag.ListProcessTree;

    List<GeneralField> generalFields = ViewBag.GeneralFields;
    List<ExtendField> extendFields = ViewBag.ExtendFields;
    List<ExtendField> tableFields = ViewBag.TableFields;
    if (Model.ListExtendField == null) { Model.ListExtendField = new List<ExtendField>() { new ExtendField() }; }
    if (Model.TableFields == null) { Model.TableFields = new List<ExtendField>() { new ExtendField() { } }; }
}
<link rel="stylesheet" type="text/css" href="@ViewBag.OssUrl/front/webuploader/webuploader.css">
<script type="text/javascript" src="@ViewBag.OssUrl/front/webuploader/webuploader.js"></script>
<script type="text/javascript" src="@ViewBag.OssUrl/front/js/common.js"></script>
<div class="layui-form layui-tab-content" style="padding:20px 40px 20px 0;">
    @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
    {
        @Html.AntiForgeryToken()

        <div class="layui-form-item">
            @Html.LabelFor(model => model.Name, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.HiddenFor(model => model.ID)
                @Html.MyEditorFor(model => model.Name)
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(model => model.NoPrefix, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.NoPrefix)
            </div>
        </div>
        if (Model.ID == 0)
        {
            <div class="layui-form-item">
                @Html.LabelFor(model => model.TableName, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.TableName)
                </div>
            </div>
        }
        <div class="layui-form-item">
            @Html.LabelFor(model => model.FormGroupID, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.FormGroupID, formGroups)
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(model => model.Sort, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.Sort)
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(model => model.Ico, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.Ico)
            </div>
        </div>



        <div class="layui-form-item">
            @Html.LabelFor(model => model.IsCustomProcess, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.IsCustomProcess)
            </div>
        </div>


        <div class="layui-form-item">
            @Html.LabelFor(model => model.Explain, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.Explain)
            </div>
        </div>


        <div class="layui-form-item">
            @Html.LabelFor(model => model.IsCustomView, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.IsCustomView)
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(model => model.HorizontalPrinting, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.HorizontalPrinting)
            </div>
        </div>
        

    <div class="layui-form-item">
        @Html.LabelFor(model => model.CallBackUrl, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            @Html.MyEditorFor(model => model.CallBackUrl)
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="submit" value="提 交" lay-submit="" lay-filter="OAForm" class="layui-btn mySubmit" />
        </div>
    </div>
}
</div>
<script type="text/javascript"> 
    $(".addItem").click(function () {
        var my_tbody = $(this).parent().parent().parent().parent().find("tbody");
        var last = my_tbody.find("tr:last");
        var lastID = last.attr("data-id");
        var currentIndex = parseInt(lastID) + 1;
        var outerHTML = last.prop('outerHTML');
        var reg = new RegExp("\\[" + lastID + "\\]", "g");
        outerHTML = outerHTML.replace('data-id="' + lastID + '"', 'data-id="' + currentIndex + '"');
        outerHTML = outerHTML.replace(reg, "[" + currentIndex + "]");
        my_tbody.append(outerHTML);
        my_tbody.find("tr:last").css("display", "");
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
    });
    $(document).on("click", ".deleteItem", function () {
        $(this).parent().parent().css("display", "none");
        $(this).parent().parent().find(".Status").val("-1");
    });

</script>
